
#ifndef SRC_DEVICE_TW80ST_H_
#define SRC_DEVICE_TW80ST_H_
#include <stdint.h>
/**
 * https://item.taobao.com/item.htm?spm=a1z09.2.0.0.49112e8dvYTs2G&id=617027961109&_u=d23dpgog5263
*/

typedef struct {
  uint8_t sof1;
  uint8_t sof2;
  uint8_t CO2_H;
  uint8_t CO2_L;
  uint8_t CH2O_H;
  uint8_t CH2O_L;
  uint8_t TVOC_H;
  uint8_t TVOC_L;
  uint8_t PM25_H;
  uint8_t PM25_L;
  uint8_t PM10_H;
  uint8_t PM10_L;
  uint8_t temperature;
  uint8_t temp_decimals;
  uint8_t humidity;
  uint8_t humdity_decimals;
  uint8_t check;
}TW80ST_t;

class TW80ST {
 public:
  void Init();
  int32_t GetValue();  // return : mg/m^3 * 1000; return < 0 sensor error
  bool Loop();
  uint32_t pm25_val_ = 0;
  uint32_t recv_time_ = 0;
  uint32_t co2_;
  uint32_t ch2o_;
  uint32_t tvoc_;
  uint32_t pm10_;
  uint32_t humdity_;
  int32_t temperature_;

 private:
  bool Pm25Parse(uint8_t ch);
};
#endif
